package com.ehotting.edsta.mqbd.monitor.web.controller;

import com.ehotting.eaf.core.domain.R;
import com.ehotting.mqbd.api.bean.MsgStateBean;
import com.ehotting.mqbd.core.manager.MqQueueManager;
import com.ehotting.mqbd.core.manager.MsgStateManager;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/queue")
@Slf4j
public class QueueController {

    @Autowired
    private MsgStateManager msgStateManager;
    @Autowired
    private MqQueueManager mqQueueManager;

//
//    @GetMapping("/isExist")
//    public Object isExist(String module,String agentId){
//        MsgStateBean msgStateBean = msgStateManager.getIfExistByAgentId(agentId);
//
//        Map<String,String> result = new HashMap<>();
//        result.put("agentId",agentId);
//        result.put("isExist",msgStateBean!=null?"1":"0");
//        return R.ok(result);
//    }

    @GetMapping("/index")
    public Object position(String module,String agentId){
        long position = 0L;// mqQueueManager.getQueueIndex(module,agentId);
        //long position = mqQueueManager.getQueueIndex(module,agentId);
        Map<String,Object> result = new HashMap<>();
        result.put("agentId",agentId);
        result.put("position",position);
        return R.ok(result);
    }

    @GetMapping("/cancel")
    public Object cancel(String agentId){
        msgStateManager.cancel(agentId);
        return R.okMsg();
    }

}